#!/usr/bin/env python

import sys
import datetime

def qps():
  qps = 0

  #for line in sys.stdin:
  with open("/tmp/grml.log", "r") as f:
    for line in f.readlines():
      ts = datetime.datetime.strptime(line.split(' ')[0], "%Y%m%d%H%M%S")
      threshold = datetime.datetime.now() - datetime.timedelta(minutes = 5)

      if ts > threshold:
        qps = qps + 1

  print "grml_qps.value %d" % (qps / (60*5))

if __name__ == "__main__":
  if sys.argv.__len__() > 1 and sys.argv[1] == "config":
    print "graph_title GRML QPS"
    print "graph_vlabel Queries Per Second"
    print "grml_qps.label QPS"
  else:
    qps()

